﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.Entities;
using UMLTouch.Domain.ClassDiagram.Items;
using UMLTouch.Core.UI;

namespace UMLTouch.Domain.ClassDiagram.Patterns
{
    public class Entity : IShapePattern
    {
        #region IShapePattern Members



        public ShapePatternMatchingResultEnum Match(Shape shape)
        {
           
            if (shape.Intersections.Any() && shape.Intersections.Any(inter=>inter.Segments.Count > 2)) 
            {
                return ShapePatternMatchingResultEnum.DontMatch;
            }

            
            if (shape.NbSegments < 4
                && shape.NbExtremityIntersections < 4
                && shape.NbMiddleIntersections == 0)
              
            {
                return ShapePatternMatchingResultEnum.MightMatch;
            }
            else if (shape.NbSegments == 4
                && shape.NbExtremityIntersections == 4
                && shape.NbMiddleIntersections == 0)
            {
                return ShapePatternMatchingResultEnum.Match;
            }
            else
            {
                return ShapePatternMatchingResultEnum.DontMatch;
            }
        }

        public Entity(String name)
        {
            Name = name;
        }


        public string Name
        {
            get;
            protected set;
        }


        public IDiagramItem GetItem(Shape shape)
        {
            return new EntityItem(shape);
        }

        public bool Equals(IShapePattern other)
        {
           return Name.Equals(other.Name,StringComparison.OrdinalIgnoreCase);
        }

        #endregion

       
    }
}
